package com.pms.action;

import com.pms.service.impl.SysUserService;
import com.pms.utils.ReturnInfo;
import com.pms.utils.User;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

@Controller
public class IndexAction {
    private Log log = LogFactory.getLog(IndexAction.class);
    @Autowired
    private SysUserService sysUserService;
    @RequestMapping("/index")
    public String index(){
        return "index";
    }
    @RequestMapping("/login")
    public String login(){
        return "login";
    }
    @RequestMapping(value = "/checkLogin", method = RequestMethod.POST)
    @ResponseBody
    public ReturnInfo checkLogin(User user, HttpServletRequest request){
        log.info("****校验 ： " + user);
        ReturnInfo info = sysUserService.checkLogin(user);
        if(info.getData() != null){
            request.getSession().setAttribute("user", info.getData());
            info.setData(null);
        }
        return info;
    }
}
